package com.hzdl.house_mgr.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzdl.house_mgr.bean.Admin;
import com.hzdl.house_mgr.bean.BaseStat;
import com.hzdl.house_mgr.mapper.AdminMapper;
import com.hzdl.house_mgr.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin login(Admin admin) {
        return adminMapper.login(admin);
    }

    @Override
    public int insertAdmin(Admin admin) {
        return adminMapper.insertAdmin(admin);
    }

    @Override
    public int deleteAdminById(Integer adminId) {
        return adminMapper.deleteAdminById(adminId);
    }

    @Override
    public int updateAdmin(Admin admin) {
        return adminMapper.updateAdmin(admin);
    }

    @Override
    public PageInfo<Admin> findAdminByWhere(Admin admin, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Admin> list = adminMapper.findAdminByWhere(admin);
        PageInfo<Admin> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Integer getCountByWhere(Admin admin) {
        return adminMapper.getCountByWhere(admin);
    }

    @Override
    public int resetAdminPwd(Integer adminId) {
        return adminMapper.resetAdminPwd(adminId);
    }

    @Override
    public int deleteSomeAdmin(String[] split) {
        int row = 0;
        if(split != null && split.length != 0){

            for(String userId : split){
                row += adminMapper.deleteAdminById(Integer.parseInt(userId));
            }
        }
        return row;
    }

    @Override
    public int updateRoleAdmin(Integer adminId, Integer[] rids) {
        int i = adminMapper.delRoleAdminByAdminId(adminId);
        int i1 = adminMapper.insRoleAdminByAdminId(adminId, rids);
        return i+i1;
    }

    @Override
    public List<BaseStat> yearSoleJson(String year) {
        return adminMapper.yearSoleJson(year);
    }
}
